<template>
    <div class="box-column container-grid">
        <ux-header-search ref="searchHeader" v-bind="enquiryData" :btnsData="{ permissionsData }"
            @search="onQueryClick"></ux-header-search>
        <div class="box-flex1 table">
            <vxe-grid v-bind="tableConfig" :data="dataStore.data" :columns="table.columns">
                <template v-slot:operate="{ row }">
                    <ux-btn-group :btns="table.btns" :data="{ row, permissionsData }"></ux-btn-group>
                </template>
                <template v-slot:facethumb="{ row }">
                    <el-image style="width: 70px; height: 40px" :src="row.face_thumb" fit="contain" v-if="row.face_thumb !== ''" :preview-src-list="[row.face_thumb]"></el-image>
                </template>
            </vxe-grid>
        </div>
        <div class="pagination-el box-row box-center-end">
            <el-pagination @size-change="onSizeChange" @current-change="onCurrentChange"
                :current-page="dataStore.proxy.page" :page-size="dataStore.proxy.pageSize" :page-sizes="dataStore.pageSizes"
                :total="dataStore.pagination.total" :layout="'total, sizes, prev, pager, next, jumper'"></el-pagination>
        </div>
        <dialogForm ref="dialogForm" @submitSuccess="onSubmitSuccess" @closeDialog="onCloseDialog"></dialogForm>
        <scripForm ref="scripForm" @submitSuccess="onSubmitSuccess" @closeDialog="onCloseDialog"></scripForm>
    </div>
</template>

<script  lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import { Action, State } from 'vuex-class';
import { mixinTableStore } from '@/mixin/table/Store';
import { mixinTableHeader } from '@/mixin/table/Header';
import { mixinTableOperation } from '@/mixin/table/Operation';
import { mixinDialogFormParent } from '@/mixin/dialog/FormParent';
import { mixinAccess } from '@/mixin/Access';
import dialogForm from './Edit.vue';
import scripForm from './Scrip.vue';
@Component({
    mixins: [
        mixinTableStore,
        mixinTableHeader,
        mixinTableOperation,
        mixinDialogFormParent,
        mixinAccess
    ],
    components: {
        dialogForm,
        scripForm
    }
})
export default class parkGuestTable extends Vue {
    @Action('parkTenant/delGuest') itemDel: any;
    @Action('parkTenant/guestList') getList: any;
    @State((state) => state.sharing.func) funcData: any;
    table: any = {
        btns: [
            {
                label: "授权门禁",
                condition: [
                    function ({ row }) {
                        return row.door_duration !== '';
                    }
                ],
                handleClick: this.onAuthDoorClick
            },
            {
                label: "授权门禁",
                param: 'scripForm',
                condition: [
                    function ({ row }) {
                        return row.door_duration == '';
                    }
                ],
                handleClick: (this as any).onEditClick
            },
            {
                label: '删除',
                condition: [
                    'permissionsData.del'
                ],
                handleClick: (this as any).onDelClick
            }
        ],
        columns: [
            {
                width: 70,
                type: 'seq',
                title: '序号'
            },
            {
                width: 100,
                title: '人员编号',
                field: 'job_number'
            },
            {

                title: '姓名',
                field: 'member_xm'
            },
            {

                title: '性别',
                field: 'member_xb',
                params: 'sexData',
                formatter: (this as any).formatterData
            },
            {


                title: '手机号',
                field: 'remark'
            },
            {
                title: '临时密码',
                field: 'door_pwd'
            },
            {
                title: '人脸',
                slots: { default: 'facethumb' },
                field: 'face_thumb'
            },
            {
                title: '门禁有效期',
                field: 'door_duration',
                formatter: function ({ cellValue }) {
                    return cellValue !== '' ? cellValue : '未授权';
                },
                className: function ({ row }) {
                    return ['', 'green ', 'red'][row.door_duration == '' ? 2 : 1];
                }
            },
            {
                min: 150,
                title: '创建时间',
                field: 'created_at'
            },
            {
                showOverflow: 'ellipsis',
                fixed: 'right',
                slots: { default: 'operate' },
                title: '操作',
                field: 'operate',
                width: 150
            }
        ]
    };

    @State((state) => state.sharing.sex) sexData: any;


    // 查询头配置
    enquiryData: any = {
        fields: [
            {
                field: 'member_xm',
                label: '姓名'
            },
            {
                field: 'remark',
                label: '手机号'
            }
        ],
        btns: [
            {
                label: '新增',
                class: 'btn-blue',
                icon: 'el-icon-plus',
                condition: ['permissionsData.add'],
                handleClick: (this as any).onAddClick
            }
        ]
    };
    onAuthDoorClick({ row }) {
        row.from = 3;
        row.door_end_time = row.door_duration;
        row.scrip_sn = row.member_sn;
        (this as any).go(
            'scripAuthDoorTable',
            {
                id: row.member_sn,
                isEdit: true,
                data: row
            },
            { isBase: true }
        );
    }
}
</script>

